package br.org.acessobrasil.processoacessibilidade.dao;

import javax.persistence.NoResultException;
import javax.persistence.Query;

import br.org.acessobrasil.processoacessibilidade.vo.FormularioPro;

public class FormularioDao extends SuperDao<FormularioPro>{

	@Override
	public FormularioPro find(long id) {
		return getEntityManager().find(FormularioPro.class, id);
	}
	
	public FormularioPro find(String action,String campos){
		try{
			Query q = getEntityManager().createQuery("Select p From FormularioPro p where p.action = ? and p.campos=?");
			q.setParameter(1, action);
			q.setParameter(2, campos);
			if(q.getResultList()!=null && q.getResultList().size()>0){
				return (FormularioPro)q.getResultList().get(0);
			}else{
				return null;
			}
		}catch(NoResultException e){
			return null;
		}
	}
	public FormularioPro findByAction(String action){
		try{
			Query q = getEntityManager().createQuery("Select p From FormularioPro p where p.action = ?");
			q.setParameter(1, action);
			if(q.getResultList()!=null && q.getResultList().size()>0){
				return (FormularioPro)q.getResultList().get(0);
			}else{
				return null;
			}
		}catch(NoResultException e){
			return null;
		}
	}
	public FormularioPro findByCampos(String campos){
		try{
			Query q = getEntityManager().createQuery("Select p From FormularioPro p where p.campos = ?");
			q.setParameter(1, campos);
			if(q.getResultList()!=null && q.getResultList().size()>0){
				return (FormularioPro)q.getResultList().get(0);
			}else{
				return null;
			}
		}catch(NoResultException e){
			return null;
		}
	}
}
